//
//  APPLEUserAccount.swift
//  123
//
//  Created by pangjiaxing on 15/12/30.
//  Copyright © 2015年 pangjiaxing. All rights reserved.
//

import UIKit

class APPLEUserAccount: NSObject {
//    Optional({
//    "access_token" = "2.00WGa9FGIbFiCB01e7b2dcd0r4QtxC";
//    "expires_in" = 157679999;
//    "remind_in" = 157679999;
//    uid = 5577490644;
//    })
    var avatar_large:String?
    var screen_name:String?
    var uid:String?
    var expires_in:NSTimeInterval = 0 {
        didSet{
            expiresDate = NSDate().dateByAddingTimeInterval(expires_in)
        }
    }
    var expiresDate:NSDate?
    var access_token:String?
    var remind_in:String?
    
    init(dict:[String:AnyObject]) {
        super.init()
        setValuesForKeysWithDictionary(dict)
    }
    override func setValue(value: AnyObject?, forUndefinedKey key: String) {
        
    }
    func encodeWithCoder(encoder:NSCoder){
        encoder.encodeObject(avatar_large, forKey: "avatar_large")
        encoder.encodeObject(screen_name, forKey: "screen_name")
        encoder.encodeObject(uid, forKey: "uid")
        encoder.encodeObject(expiresDate, forKey: "expiresDate")
        encoder.encodeObject(access_token, forKey: "access_token")
        encoder.encodeObject(remind_in, forKey: "remind_in")
    }
    required init?(coder decoder:NSCoder) {
        avatar_large = decoder.decodeObjectForKey("avatar_large") as? String
        screen_name = decoder.decodeObjectForKey("screen_name") as? String
        uid = decoder.decodeObjectForKey("uid") as? String
        expiresDate = decoder.decodeObjectForKey("expiresDate") as? NSDate
        access_token = decoder.decodeObjectForKey("access_token") as? String
        remind_in = decoder.decodeObjectForKey("remind_in") as? String
    }
    
    override var description : String{
        
        let keys = ["uid", "expires_in", "access_token", "remind_in", "avatar_large", "screen_name"]
        
        return dictionaryWithValuesForKeys(keys).description
    }
}
